Filtering Fields on the v2 API

I’m trying to make some changes to a script that curls the old API so it can use the new API. The script filters the fields for incident_number and ID. I’ve looked up the documentation and can’t seem to find the docs that will let get those two things as I only end up getting all the things. Below is an example of the two curl commands. I’ve tried a few things as stated in the docs but haven’t had much luck.

Curl Using the Old API
curl -X GET --header ‘Accept: application/json’ --header ‘Authorization: Token token=SuperSecretTOKEN’ ‘https://subdomain.pagerduty.com/api/v1/incidents?fields=incident_number,id’

Curl Using the New API
curl -X GET --header ‘Accept: application/vnd.pagerduty+json;version=2’ --header ‘Authorization: Token token=SuperSecretTOKEN’ ‘https://api.pagerduty.com/incidents’

Hi Jose,

Thanks for the details.

You’d just need to append /{incident_id} to the new API endpoint. So the curl command should be:

curl -X GET --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Authorization: Token token=SuperSecretTOKEN' 'https://api.pagerduty.com/incidents/{id}'

You can read further about this endpoint on our documentation here: https://v2.developer.pagerduty.com/v2/page/api-reference#!/Incidents/get_incidents_id

Cheers,

Jay

Hey Jay

Thanks for getting back to me. Unfortunately gets me more info than I really need at them moment. What I’m looking for is more of a filter so I only get the incident_numbers and ids much like the old curl command used to let me do. Any ideas on how to achieve that?

Thanks again for the help.

Jose,

The API v2 does not support filtering to only return specific fields like incident id and number (see a list of available incident filters), but I was able to filter down to just incident id and number using JQ to process the response:

curl -X GET --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Authorization: Token token=SuperSecretTOKEN' 'https://api.pagerduty.com/incidents' | jq '{incidents: [.incidents[] | {incident_number: .incident_number, id: .id}]}